package com.neuedu.javase.io;

import java.io.*;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-10-05 14:04
 * 描述 :  Serializable :   java.io.NotSerializableException: com.neuedu.javase.io.Teacher
 * java.io.InvalidClassException
 * teacerh.ttt 中（类信息）不存在  age属性，toString方法
 */
public class Teacher implements Serializable {

    private static final long serialVersionUID = 1L;
    private String name;
    private Double age;

    public Teacher(String name) {
        this.name = name;
    }

    public Teacher(String name, Double age) {
        this.name = name;
        this.age = age;
    }


    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


//    @Override
//    public String toString() {
//        return "Teacher{" +
//                "name='" + name + '\'' +
//                '}';
//    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {


        Teacher teacher = new Teacher("张飞");

        //serialVersionUID 1;
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\io\\teacerh.ttt"))   ;
//        oos.writeObject(teacher);
//        oos.close();


        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\io\\teacerh.ttt") );
        Object obj = ois.readObject();
        System.out.println("obj = " + obj);
        ois.close();

    }






}
